﻿function f_clientWidth() {
	return f_filterResults (
		window.innerWidth ? window.innerWidth : 0,
		document.documentElement ? document.documentElement.clientWidth : 0,
		document.body ? document.body.clientWidth : 0
	);
}
function f_clientHeight() {
	return f_filterResults (
		window.innerHeight ? window.innerHeight : 0,
		document.documentElement ? document.documentElement.clientHeight : 0,
		document.body ? document.body.clientHeight : 0
	);
}
function f_scrollLeft() {
	return f_filterResults (
		window.pageXOffset ? window.pageXOffset : 0,
		document.documentElement ? document.documentElement.scrollLeft : 0,
		document.body ? document.body.scrollLeft : 0
	);
}
function f_scrollTop() {
	return f_filterResults (
		window.pageYOffset ? window.pageYOffset : 0,
		document.documentElement ? document.documentElement.scrollTop : 0,
		document.body ? document.body.scrollTop : 0
	);
}
function f_filterResults(n_win, n_docel, n_body) {
	var n_result = n_win ? n_win : 0;
	if (n_docel && (!n_result || (n_result > n_docel)))
		n_result = n_docel;
	return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
}

function DoTip(Element, theTip)
{
   Element.onmouseover = function() {Tip(theTip, BALLOON, true);}
   Element.onmouseout = function() {UnTip();}
}

function getWindowWidthHeight()
{
   var theWidth, theHeight;
   // Window dimensions:
   if (window.innerWidth) {
   theWidth=window.innerWidth;
   }
   else if (document.documentElement && document.documentElement.clientWidth) {
   theWidth=document.documentElement.clientWidth;
   }
   else if (document.body) {
   theWidth=document.body.clientWidth;
   }
   if (window.innerHeight) {
   theHeight=window.innerHeight;
   }
   else if (document.documentElement && document.documentElement.clientHeight) {
   theHeight=document.documentElement.clientHeight;
   }
   else if (document.body) {
   theHeight=document.body.clientHeight;
   }
   
   var result = {};
   result["Width"] = theWidth;
   result["Height"] = theHeight;
   
   return result;
}

function WriteHistory(message)
{
	var historyDiv = document.getElementById('History1');
	if(historyDiv){
		historyDiv.insertBefore(document.createElement('BR'), historyDiv.firstChild);
		historyDiv.insertBefore(document.createTextNode(message), historyDiv.firstChild);

		historyDiv.scrollTop += 50;
	}
}

function setCaretPosition(elemId, caretPos) {
    var elem = document.getElementById(elemId);

    if(elem != null) {
        if(elem.createTextRange) {
            var range = elem.createTextRange();
            range.move('character', caretPos);
            range.select();
        }
        else {
            if(elem.selectionStart) {
                elem.focus();
                elem.setSelectionRange(caretPos, caretPos);
            }
            else
                elem.focus();
        }
    }
}

//Google Search - Main Page
function doSearch()
{
if (document.getElementById('query').value.length > 0)
    winopen_withlocationbar("http://www.google.com/search?q=" + encodeURI(document.getElementById('query').value));
else
   alert("Please enter something to search");    
}

//Queue Ajax Postbacks
var prm = Sys.WebForms.PageRequestManager.getInstance();
prm.add_initializeRequest(InitializeRequestHandler);
prm.add_beginRequest(BeginRequestHandler);
prm.add_endRequest(EndRequestHandler);        
  
var pbQueue = new Array();
var currentItem = new Object();

function InitializeRequestHandler(sender, args) {
   WriteHistory("InitializeRequestHandler"); 
   WriteHistory(args.get_postBackElement() + " | " + args.get_postBackElement().id);
   if (args.get_postBackElement() != null)
   {
      if (prm.get_isInAsyncPostBack()) {
         WriteHistory("Async: " + args.get_postBackElement());

         var isCancel = true;         
         var theID = args.get_postBackElement().id;
         
         //Check if is tab post back, if it is, ignore the queue, and do a post back immedicately
         if (theID.length > 4)
         {
            if (theID.substring(0,4) == "tlbl")
            {
               if (!isNaN(theID.substring(4)))
               {
                  pbQueue = new Array();  
                  isCancel = false;
               }
            }
         }
         
         if (isCancel)
         {
            args.set_cancel(true);
            
            var PostBackID = args.get_postBackElement().id;
            if (parseInt(PostBackID) != 'NaN' && parseInt(PostBackID) > 0)
            {
               //this is a page change, clear out existing items in queue
               pbQueue = new Array();
            }
            
            pbQueue.push({'PostBackElement': args.get_postBackElement().id,
            'EventArgument': document.forms[0].__EVENTARGUMENT.value});
         }
      }
      else
      {

         currentItem = {'PostBackElement': args.get_postBackElement().id,
            'EventArgument': document.forms[0].__EVENTARGUMENT.value};
      }
   }
   else
   {
      WriteHistory("NULL on InitializeRequestHandler");
   }
}       

 function BeginRequestHandler(sender, args) {
     pbControl = args.get_postBackElement();  //the control causing the postback
     //pbControl.disabled = true;
 }
    
function EndRequestHandler(sender, args) {
   if (pbQueue.length > 0) {
      currentItem = pbQueue.shift();
      __doPostBack(currentItem.PostBackElement.replace("_","$"), currentItem.EventArgument);
   }
   else
   {
      //currentItem.PostBackElement.disabled = false;
   }
}

if( typeof Proxy == "undefined" ) Proxy = ProxyAsync;


function onTabDrop(e)
{
   WidgetService.ReorderPage(e.Element.substring(3), e.Position);
   
   //window.status= "Moving Tab #" + e.Element.substring(3) + ":" + e.Parent.id + ":" + e.Position;
   WriteHistory("Moving Tab #" + e.Element.substring(3) + " to position #" + e.Position);
}

function onDrop( sender, e )
{
    var container = e.get_container();
    var item = e.get_droppedItem();
    var position = e.get_position();
    
    //alert( String.format( "Container: {0}, Item: {1}, Position: {2}", container.id, item.id, position ) );
    
    var instanceId = parseInt(item.getAttribute("InstanceId"));
    var columnNo = parseInt(container.getAttribute("columnNo"));
    var row = position;
    WidgetService.MoveWidgetInstance( instanceId, columnNo, row );
}

function onDrop2( sender, e )
{
}

function $hide(id)
{
   var element = document.getElementById(id);
   if (element == null)
   {      
      //alert(id + " is invalid");
   }
   else
      element.style.display="none";
}
function $show(id)
{
   var element = document.getElementById(id);
   if (element == null)
   {
      //alert(id + " is invalid");
   }
   else
      element.style.display="block";
}

function $show_inline(id)
{
   var element = document.getElementById(id);
   if (element == null)
   {
      //alert(id + " is invalid");
   }
   else
      element.style.display="inline";
}

function pageUnload()
{
    
}

function showHint(theURL, theLink, theDiv)
{
    var request = new Sys.Net.WebRequest();
    request.set_httpVerb("GET");
    request.set_url(theURL);
    request.add_completed( function( executor )
    {
        if (executor.get_responseAvailable()) 
        {
            var helpDiv = $get(theDiv);
            var helpLink = $get(theLink);
            
            var helpLinkBounds = Sys.UI.DomElement.getBounds(helpLink);
            
            helpDiv.style.top = (helpLinkBounds.y + helpLinkBounds.height) + "px";
            
            var content = executor.get_responseData();
            helpDiv.innerHTML = content;
            helpDiv.style.display = "block";                       
        }
    });
    
    var executor = new Sys.Net.XMLHttpExecutor();
    request.set_executor(executor); 
    executor.executeRequest();
}

function showAbout()
{
   showHint('about.aspx', 'HelpLink', 'HelpDiv');
}

var Utility = 
{
    // change to display:none
    nodisplay : function(e) 
    { 
        if( typeof e == "object") e.style.display = "none"; else if( $get(e) != null ) $get(e).style.display = "none"; 
    },
    // change to display:block
    display : function (e,inline) 
    { 
        if( typeof e == "object") e.style.display = (inline?"inline":"block"); else if( $get(e) != null ) $get(e).style.display = (inline?"inline":"block"); 
    },
    getContentHeight : function()
        {
        if( document.body && document.body.offsetHeight ) {
            return document.body.offsetHeight;
        }
    },


    blockUI : function()
    {
        Utility.display('blockUI');
        var blockUI = $get('blockUI');
    
        if( blockUI != null ) // it will be null if called from CompactFramework
        blockUI.style.height = Math.max( Utility.getContentHeight(), 1000) + "px";    
    },

    unblockUI : function()
    {
        Utility.nodisplay('blockUI');
    }
};

function winopen(url, w, h) 
{
  var left = (screen.width) ? (screen.width-w)/2 : 0;
  var top  = (screen.height) ? (screen.height-h)/2 : 0;

  window.open(url, "_blank", "width="+w+",height="+h+",left="+left+",top="+top+",resizable=yes,scrollbars=yes");
  
  return;
}

function winopen_withlocationbar(url) 
{
 var w = screen.width / 2;
 var h = screen.height /2;
  var left = (screen.width) ? (screen.width-w)/2 : 0;
  var top  = (screen.height) ? (screen.height-h)/2 : 0;

  window.open(url, "_blank");
  
  return;
}

function winopen2(url,target, w, h) 
{
  var left = (screen.width) ? (screen.width-w)/2 : 0;
  var top  = (screen.height) ? (screen.height-h)/2 : 0;

 if(popupWin_2[target] != null)
	if(!popupWin_2[target].closed)
		popupWin_2[target].focus();
	else
		popupWin_2[target] = window.open(url, target, "width="+w+",height="+h+",left="+left+",top="+top+",resizable=yes,scrollbars=yes");
  else
	popupWin_2[target] = window.open(url, target, "width="+w+",height="+h+",left="+left+",top="+top+",resizable=yes,scrollbars=yes");
  
  return;
}

//Object to store the references to all the Widgets in the Page
var PageWidgets = function()
{
   this.Widgets = new Array();
   
   this.Push = function(element)
   {
      this.Widgets.push(element);
   }
   
   this.ClearWidgets = function()
   {
      //when changing page, clear all widgets      
      this.abort();
      this.Widgets = new Array();
   }
   
   this.Load = function()
   {
   	for(var i=0;i<this.Widgets.length;i++)
	   {
   	   this.Widgets[i].Load();
	   }   
   }
   
   this.abort = function()
   {   
      AjaxPro.queue.abort();
   }
}
var _PageWidgets = new PageWidgets();

//Object to store the references to all the tabs in the Page
var PageTabs = function()
{
   this.Tabs = new Array();
   this.Push = function(element)
   {
      if (this.Find(element.PageID) == null)
      {
         this.Tabs.push(element);
      }
   }
   
   this.Remove = function(element)
   {
      //Remove the element from the array
      var elementID = -1;
      for(var i=0;i<this.Tabs.length;i++)
      {
         if (this.Tabs[i].PageID == element.PageID)
         {
            elementID = i;
            break;
         }            
      }
      
      if (elementID > -1)
      {
         this.Tabs.splice(elementID, 1);
      }   
   }
   
   this.Find = function(PageID)
   {
      for(var i=0;i<this.Tabs.length;i++)
      {
         if (this.Tabs[i].PageID == PageID)
            return this.Tabs[i];
      }
      
      return null;
   }
   
   this.Load = function() {
      for(var i=0;i<this.Tabs.length;i++)
      {
         this.Tabs[i].Load();
      }
   }
}
var _PageTabs = new PageTabs();


var myTab = function(element)
{
   this.name = element.MySelf;
   this.id = element.MySelf;
   this.PageID = element.PageID;
   this.TitleLabel = element.TitleLabel;
   this.TitleTextBox = element.TitleTextBox;
   this.inEditMode = false;
   this.isActive = (element.isActive == 1);
   this.UpdatePanel = element.UpdatePanel;
   this.eventName = this.TitleLabel;
   _PageTabs.Push(this);
   
   this.Load = function()
   {
      if( !Array.contains( prm._asyncPostBackControlIDs, this.eventName) )
         prm._asyncPostBackControlIDs.push(this.eventName);

      if( !Array.contains( prm._asyncPostBackControlClientIDs, prm._uniqueIDToClientID(this.eventName)) )
         prm._asyncPostBackControlClientIDs.push(prm._uniqueIDToClientID(this.eventName));

      this.inEditTitleMode=false;
      var theLabel = document.getElementById(this.TitleLabel);
      var theTextBox = document.getElementById(this.TitleTextBox);
      
      if (this.isActive)
      {
         theLabel.Title = "Click to change tab title";
         DoTip(theLabel, "Click to change tab title");
      }
      else
      {
         theLabel.Title = "Click to navigate to this tab";
         DoTip(theLabel, "Click to navigate to this tab");
      }
      
      if(theLabel && theTextBox && theLabel != null && theTextBox != null)
      {
         $hide(this.TitleTextBox);
         $show_inline(this.TitleLabel);

         theTextBox.value = theLabel.innerHTML;
         var theFunction = this.id + '.ToggleTitle(0);';
         var theFunction1 = this.id + '.ToggleTitle(1);';
         theLabel.onclick = function(){eval(theFunction);return false;};
         theTextBox.onblur = function(){eval(theFunction1);return false;};
         
         if (is_ie)
         {
            theTextBox.onkeypress = function(){if(event.keyCode==13){eval(theFunction1);event.keyCode=0;return false;}};
         }
         else
         {
            theTextBox.onkeypress = function(event){if(event.keyCode==13){eval(theFunction1);return false;}};
         }
      }
   }
   
   this.Delete = function()
   {
      if (_PageTabs.Tabs.length > 1)
      {
         if (confirm("Are you sure you want to delete this tab?"))
         {
            //remove this node from the tabs
            WidgetService.DeletePage(this.PageID);
            
            //Remove the element from the array
            _PageTabs.Remove(this);
            
            //Remove the element from the page
            //TitleTextBox and Label are in the same level
            //have to remove their parentnode from the grandparent node
            //i.e remove the li from the ul
           var theNode = document.getElementById(this.TitleTextBox);
           if (theNode != null)
           {
              theNode = theNode.parentNode;
              if(theNode!= null)
              {
                  //tell the parent to remove me
                 theNode.parentNode.removeChild(theNode);
              }
           }
         }
      }
      else
      {
         alert("You cannot delete your last tab");
      }
   }
   
   this.ToggleTitle = function()
   {
      var theLabel = document.getElementById(this.TitleLabel);
      if (this.isActive==true)
      {
         var theTextBox = document.getElementById(this.TitleTextBox);

         if (arguments.length > 0)
         {
            //hardcoded inEditTitleMode
            if (arguments[0] == 1)
               this.inEditTitleMode=true;
            else
               this.inEditTitleMode=false;
         }
         
         //alert(this.id + '\n' + this.inEditTitleMode + '\n' + theLabel + '\n' + theTextBox + '\n' + this.TitleLabel + '\n' + this.TitleTextBox);
         if(theLabel != null && theTextBox != null)
         {
            if (this.inEditTitleMode)
            {
               WriteHistory("Tab #" +  this.id + " text edit end");
               this.inEditTitleMode = false;
               $show_inline(this.TitleLabel);
               $hide(this.TitleTextBox);
               
               if (theLabel.innerHTML != theTextBox.value)
               {
                  theLabel.innerHTML = theTextBox.value;
                  WidgetService.ChangePageName(this.PageID, theTextBox.value);
                  WriteHistory("Change " + this.PageID + " title to " + theTextBox.value);
               }
            }
            else
            {
               WriteHistory("Tab #" +  this.id + " text edit start");
               this.inEditTitleMode = true;
               $show_inline(this.TitleTextBox);
               $hide(this.TitleLabel);
               //theTextBox.style.width='98%';
               theTextBox.value = theLabel.innerHTML;
               theTextBox.focus();
               setCaretPosition(this.TitleTextBox, theTextBox.value.length);
            }
         }
      }
      else
      {
         var div_ChangePageInProcess = document.getElementById("ChangePageInProcess");
         var currentWindowWidthHeight = getWindowWidthHeight();
         div_ChangePageInProcess.style.marginTop = currentWindowWidthHeight.Height / 4;
         div_ChangePageInProcess.style.marginBottom = div_ChangePageInProcess.style.marginTop;
         $show("ChangePageInProcess")
         $hide(pg_ColumnUpdatePanel);
         //Change Page
         _PageWidgets.ClearWidgets();
         //prm._doPostBack(this.eventName,'');
         __doPostBack(this.eventName, '');
      }
   }
}

Widget = function(element) {
    this.name = element.MySelf
    this.id = element.MySelf
    this.instanceID = element.instanceID;
    this.PageID = element.PageID;
    this.BehaviorID = element.BehaviorID;
    this.SettingsPanel = element.SettingsPanel;
    this.BodyPanel = element.BodyPanel;
    this.Settings = {};
    this.hasViewState = element.hasViewState;
    this.inEditMode = false;
    this.RefreshWidget = element.RefreshBtn;
    this.FirstLoad = Date();
    this.LastRefresh = this.FirstLoad;
    this.TitleLabel = element.TitleLabel;
    this.TitleTextBox = element.TitleTextBox;
    this.inEditTitleMode = false;
    
    this.CPEBtn = document.getElementById(element.CPEBtn);
    this.EditWidgetBtn = document.getElementById(element.EditWidgetBtn);

    //JSON Parameters
    this.isJSON = element.isJSON;
    this.LastUpdateLbl = document.getElementById(element.LastUpdateLbl);
   
   this.BodyLoadingPanel = "";
   this.BodyDataPanel = "";
    _PageWidgets.Push(this);
   
   this.Load = function()
   {
      //alert(this.TitleLabel + '\n' + this.TitleTextBox);
      this.SetupTitle();
      
      if (this.RefreshWidget)
      {
         var theBtn = $get(this.RefreshWidget);
         if (theBtn)
            DoTip(theBtn, "Click to refresh the contents of this widget");
      }
      
      if (this.EditWidgetBtn)
      {
         DoTip(this.EditWidgetBtn, "Click to edit the settings for this widget");
      }
      
      //set the top div to auto height
      var element = $get(this.BodyPanel);
      if (element)
         element.parentNode.parentNode.parentNode.style.height="auto"      
   }
   this.AssignSettings = function(obj)
   {
      this.Settings = obj;
   }
   this.UpdateParameters = function(element)
   {
    this.instanceID = element.instanceID;
    this.PageID = element.PageID;
    this.BehaviorID = element.BehaviorID;
    this.SettingsPanel = element.SettingsPanel;
    this.BodyPanel = element.BodyPanel;
    this.Settings = {};
    this.hasViewState = element.hasViewState;
    this.inEditMode = false;
    this.TitleLabel = element.TitleLabel;
    this.TitleTextBox = element.TitleTextBox;
    
    this.CPEBtn = document.getElementById(element.CPEBtn);
    this.EditWidgetBtn = document.getElementById(element.EditWidgetBtn);
    this.LastUpdateLbl = document.getElementById(element.LastUpdateLbl);
   }
   
   this.SetupTitle = function()
   {
      this.inEditTitleMode=false;
      var theLabel = document.getElementById(this.TitleLabel);
      var theTextBox = document.getElementById(this.TitleTextBox);
      
      if(theLabel && theTextBox && theLabel != null && theTextBox != null)
      {
         $hide(this.TitleTextBox);
         $show(this.TitleLabel);
         //Show the label, hide the textbox
         //theLabel.style.display = "block";
         //theTextBox.style.display = "none";
         theTextBox.value = theLabel.innerHTML;
         var theFunction = this.id + '.ToggleTitle(0);';
         var theFunction1 = this.id + '.ToggleTitle(1);';
         theLabel.onclick = function(){eval(theFunction);return false;};
         DoTip(theLabel,"Click to edit the widget title");
         theTextBox.onblur = function(){eval(theFunction1);return false;};

         if (is_ie)
         {
            theTextBox.onkeypress = function(){if(event.keyCode==13){eval(theFunction1);event.keyCode=0;return false;}};
         }
         else
         {
            theTextBox.onkeypress = function(event){if(event.keyCode==13){eval(theFunction1);return false;}};
         }
      }
   }

   this.ToggleTitle = function()
   {
      var theLabel = document.getElementById(this.TitleLabel);
      var theTextBox = document.getElementById(this.TitleTextBox);

      if (arguments.length > 0)
      {
         //hardcoded inEditTitleMode
         if (arguments[0] == 1)
            this.inEditTitleMode=true;
         else
            this.inEditTitleMode=false;
      }
      
      //alert(this.id + '\n' + this.inEditTitleMode + '\n' + theLabel + '\n' + theTextBox + '\n' + this.TitleLabel + '\n' + this.TitleTextBox);
      if(theLabel != null && theTextBox != null)
      {
         if (this.inEditTitleMode)
         {
            WriteHistory("Widget #" +  this.id + " text edit end");
            this.inEditTitleMode = false;
            $show(this.TitleLabel);
            $hide(this.TitleTextBox);
            
            if (theLabel.innerHTML != theTextBox.value)
            {
               theLabel.innerHTML = theTextBox.value;
               WidgetService.ChangeWidgetName(this.PageID, this.instanceID, theTextBox.value);
            }
         }
         else
         {
            WriteHistory("Widget #" +  this.id + " text edit start");
            this.inEditTitleMode = true;
            $show(this.TitleTextBox);
            $hide(this.TitleLabel);
            theTextBox.style.width='98%';
            theTextBox.value = theLabel.innerHTML;
            theTextBox.focus();
            setCaretPosition(this.TitleTextBox, theTextBox.value.length);
         }
      }
   }
   
    this.Save = function(RefreshOnSave)
    {
      this.HideSettings();
      var oSettings = {};
      var hasSettings = false;
      for(var key in this.Settings)
      {
         hasSettings = true;
         var value = this.Settings[key];
         if ((typeof(key) != 'undefined' && key != null) 
         && (typeof(value) != 'undefined' && value != null))
         {
            var element = document.getElementById(value);
            var val = "";
            if (element == null)
            {
               val = value;
            }
            else
            {
               val = element.value;
            }
            
            if (key.toLowerCase().indexOf("password") > -1)
            {
               if (key.toLowerCase().indexOf("ignore") < 0)
               {
                  if (val.length > 0)
                     oSettings[key] = RsaSecurityHelper.encrypt(val);
                  else
                     oSettings[key] = "";
               }  
               
               if (element != null)
                  element.value = "";
            }
            else
            {
               if (key.toLowerCase().indexOf("ignore") < 0)
               {
                  oSettings[key] = val;
               }
            }
         }
      }
      
      if (hasSettings)
      {
         WidgetService.SaveWidgetSettings(this.instanceID, this.PageID, oSettings);
        
         
         if (RefreshOnSave == null || RefreshOnSave)
         {
            if (this.isJSON)
            {
               this.Refresh();
            }
            else
            {
               if (!this.hasViewState)
               {
                  //if there is no viewstate, .net does not remember what's inside the panels, so we can clear it to reduce the traffic
                  document.getElementById(this.SettingsPanel).innerHTML = "";
               }
               Sys.WebForms.PageRequestManager.getInstance()._doPostBack('WidgetContainer' + this.instanceID + '$RefreshWidget','');
            }
         }         
      }
    }
    
    this.ShowSettings = function()
    {
      if (this.EditWidgetBtn != null)
      {
         this.EditWidgetBtn.innerHTML = "Cancel Edit";
         $show(this.SettingsPanel);         
         $hide(this.BodyPanel);
         this.inEditMode = true;

         var element = $get(this.SettingsPanel);
         if (element)
         element.parentNode.parentNode.parentNode.style.height="auto"
         DoTip(this.EditWidgetBtn, "Click to cancel editing the settings for this widget");
      }
    }
    
    this.HideSettings = function()
    {
      if (this.EditWidgetBtn != null)
      {
         this.EditWidgetBtn.innerHTML = "Edit";
         $hide(this.SettingsPanel);
         $show(this.BodyPanel);
         this.inEditMode = false;
         
         var element = $get(this.BodyPanel);
         if (element)
         element.parentNode.parentNode.parentNode.style.height="auto"
         DoTip(this.EditWidgetBtn, "Click to edit the settings for this widget");
      }
    }
       
    this.ToggleSettings = function()
    {
      if (this.inEditMode)
      {
         this.HideSettings();
      }
      else
      {
         this.ShowSettings();
      }
    }
    
    this.ExpandCollapse = function()
    {
      if ($find(this.BehaviorID).get_Collapsed())
      {
         WidgetService.ToggleWidgetInstance(this.instanceID, true, this.PageID);
         this.CPEBtn.className = "widget_footer_expand";
         DoTip(this.CPEBtn, "Click to collapse this widget");
      }
      else
      {
         WidgetService.ToggleWidgetInstance(this.instanceID, false, this.PageID);
         this.CPEBtn.className = "widget_footer_collapse";
         DoTip(this.CPEBtn, "Click to expand this widget");
      }    
    }
    
    this.Delete = function()
    {
      if (confirm("Are you sure you want to delete this widget?"))
      {
         WidgetService.DeleteWidgetInstance(this.instanceID);
         $hide("WidgetContainer" + this.instanceID + "_Widget");
      }    
    }

   this.Display = function()
   {
    var x = "";
          for(var key in this.Settings)
          {
          x = x + key + ':' + this.Settings[key] + '\n';            
          }

      alert(this.FirstLoad + '\n' + this.LastRefresh + '\n' + x);         
   }  
     
    this.Refresh = function()
    {
      if (this.BodyDataPanel != null && this.BodyDataPanel.length > 0 &&
      this.BodyLoadingPanel != null && this.BodyLoadingPanel.length > 0)
      {
         $show(this.BodyLoadingPanel);
         $hide(this.BodyDataPanel);         
         this.LoadData();
         this.LastRefresh = Date();                  
      }
      else
      {
         WriteHistory(this.BodyDataPanel + " : " + this.BodyLoadingPanel);
      }
    }
    
    this.LoadData = function()
    {    
    }
    
    this.ServerCallBack = function(res) {
         var x = "";
         for(var key in res)
         {
            x += key + " : " + res[key] + "<hr>";
         }
         
         alert(x);         
    }
}

function PageFirstLoad()
{
   setTimeout(function(){
   var today = new Date();
   WriteHistory("PageFirstLoad @ " + today);
   CreateDragContainer(document.getElementById('tabList'));
	dragHelper = document.createElement('DIV');
	dragHelper.style.cssText = 'position:absolute;display:none;';

	document.body.appendChild(dragHelper);   
	}, 50);
	
   $hide("ChangePageInProcess")
   $show(pg_ColumnUpdatePanel);

	_PageTabs.Load();
	_PageWidgets.Load();
}


Sys.WebForms.PageRequestManager.getInstance().add_pageLoaded(PageFirstLoad)
if(typeof(Sys) !== "undefined")Sys.Application.notifyScriptLoaded();